package jd.util;

import javax.swing.filechooser.FileFilter;
import java.io.File;

/**
 * Created by wangpengzhi1 on 2018/8/2.
 */
public  class ExcelFileFilter extends FileFilter {

    String ext;
    public ExcelFileFilter(String ext) {

        this.ext = ext;
    }
    public boolean accept(File file) {
       if (file.isDirectory())
       {
        return true;
       }
        String fileName = file.getName();
        int index = fileName.lastIndexOf('.');
        if(fileName.endsWith(ext))  return true;

       if (index > 0 && index < fileName.length() - 1)
        {
            String extension = fileName.substring(index + 1).toLowerCase();
            if (extension.contains(ext))
                return true;
        }
       return false;
    }
    public String getDescription() {
        if (ext.equals("xls"))
        {
            return "Microsoft Excel文件(*.xls)";
        }
        if(ext.equals("exe"))
        {
            return "可执行文件(*.exe)";
        }
        return "";
    }

}


